package com.example.activiti.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.activiti.dto.publicDto.ActivitiResponseDto;
import com.example.activiti.service.ActivitiReturnService;

@RestController  
@RequestMapping("/activitiReturnController")
public class ActivitiReturnController {
	@Autowired
	private ActivitiReturnService activitiReturnService;
	
	/**
	 * 拒绝功能（默认都回到初始化节点）
	 * 在任意节点拒绝后自动回到发起人节点，发起人重新提交后流程重新开始。
	 * 那么面临的两个问题是
	 * (1)流程图中没有发起人节点，怎么造出这个发起人节点
	 * (2)流程已经在流转中了，如何重新流转
	 * 
	 */
	@PostMapping("/refuseToStart")
	public ActivitiResponseDto refuseToStart(@RequestParam("taskId")String taskId, 
			@RequestParam("assignee")String assignee, 
			@RequestParam("opinion")String opinion) {
		return activitiReturnService.refuseToStart(taskId, assignee, opinion);
	}
	
	/**
	 * 撤回发布的流程
	 * @param instanceId 流程实例id
	 * @param deleteReason 删除原因
	 */
	@PostMapping("/delInstance")
	public void delInstance(@RequestParam("instanceId")String instanceId, 
			@RequestParam("deleteReason")String deleteReason) {
		activitiReturnService.delInstance(instanceId, deleteReason);
	}
}
